/**
 * 模态框
 */
module.exports = function ($scope, $state, $stateParams,$resource,$modal, toaster) {
	/* 分页
     * ========================================= */
    $scope.maxSize = 5;             //最多显示多少个按钮
    $scope.currentPage = 1;      //当前页码
    $scope.itemsPerPage = 10         //每页显示几条
	


	$scope.pageChanged = function () {
       var para = {
            pageNo:$scope.currentPage,
            pageSize:$scope.itemsPerPage,
        };
		$resource('/api/as/dsc/traffic/findCarList ', {}, {}).
		save({}, function(res){			
			if(res.errcode !== 0){
				toaster.error({title:"",body:res.errmsg});
			}else{
				console.log(res);
				$scope.objs=res.data.results;									
				$scope.totalItems = res.data.totalRecord;
			}
		});
    };
	$scope.pageChanged();

	$scope.addcar= function (car_code) {	
		var modalInstance = $modal.open({
			template: require('../views/add_car.html'),
			controller: 'add_car',
			size: 'lg',
			resolve: {
				car_code: function () {
					return car_code;
				}
			}
		});
		modalInstance.result.then(function (showResult) {	
				$scope.pageChanged();
		});
	}
	

	$scope.edit= function (car_code) {	
		var modalInstance = $modal.open({
			template: require('../views/add_car.html'),
			controller: 'add_car',
			size: 'lg',
			resolve: {
				car_code: function () {
					return car_code;
				}
			}
		});
		modalInstance.result.then(function (showResult) {	
				$scope.pageChanged();
		});
	}



	$scope.seeinfo = function(car_code){
		$state.go('app.carinfo', {'car_code' : car_code});
	}


			$scope.search=function(){
			var dic = {
				pageNo:$scope.currentPage,
            	pageSize:$scope.itemsPerPage,
				
			}
				
				$resource('', {}, {}).save(dic, function(res){
                if(res.errcode === 0 || res.errcode === 10003){
                    // console.log(res);
					$scope.objs=res.data.results;
                    $scope.totalItems = res.data.totalRecord;
                }else{
                    alert(res.errmsg);
                }
            });
			}

			// $scope.apply= function (index) {    
			// 	console.log($scope.objs[index].project_code) ;          
			// 	 if(confirm('是否推荐此项目？')){
			// 		$resource('/api/as/ggc/reviewDistrictTourism/updateByRecommend', {}, {}).save({'project_code':$scope.objs[index].project_code}, function(res){			              
            //     if(res.errcode === 0 || res.errcode === 10003){
			// 			alert('推荐成功')			
			// 			$scope.pageChanged();
            //     }else{
            //         alert(res.errmsg);
            //     }
            // });
				
			// 	 }		
				 
			// }

            

}